<?php
	class Topic extends MY_controller{

		function __construct(){
			parent::__construct();
		}

		public function index($tk_category_id = 0, $limit = 0){
			$this->load->model("Tk_categorys");
			$this->load->model("Subjects");
			$conditions['school_id'] = $this->school_id;
			$conditions['uid'] = $this->user_data['id'];
			$conditions['tk_category_id'] = $tk_category_id;
			$tk_category_list = array();
			$subject_list = $this->Subjects->get_school_subject_list($limit, $this->offset = 9, $conditions);

			$this->load->library('pagination');
			$page_config['base_url'] = '/topic/index/' . $tk_category_id;
			$page_config['total_rows'] = $subject_list['count'];
			$page_config['per_page'] = $this->offset;
			$page_config['uri_segment'] = 4;
			$this->pagination->initialize($page_config);
			$pagination = $this->pagination->create_links();

			// print_r($subject_data);exit;
			$tk_category_list = $this->Tk_categorys->get_tk_category_list(0, 0, $conditions);
			
			//获取一条直播
			$this->load->model('lives');
			$zhibo = $this->lives->get_last_zhibo();
			if($zhibo){
				$time = time();
				if($zhibo['start_time'] < $time && $time < $zhibo['end_time']){
					$zhibo['live_status'] = 2;
				}
				if($zhibo['start_time'] > $time){
					$zhibo['live_status'] = 1;
				}
				if($zhibo['end_time'] < $time){
					$zhibo['live_status'] = 3;
				}
				$this->smarty->assign("zhibo", $zhibo);
			}
			
			$this->load->model('Advertisings');
			$ad_conditions['ad_position_sign'] = "topic_banner";
	        $ad_conditions['school_id'] = $this->school_id;
	        $banner_list = $this->Advertisings->get_list($ad_conditions);
			$this->smarty->assign("banner_list", $banner_list);
			$this->smarty->assign("tk_category_id", $tk_category_id);
			$this->smarty->assign("tk_category_list", $tk_category_list['result']);
			$this->smarty->assign("menu_id", 5);
			$this->smarty->assign("pagination", $pagination);
			$this->smarty->assign("subject_list", $subject_list);
			$this->smarty->assign("tk_category_list", $tk_category_list);
			$this->smarty->display("tiku/index.html");
		}
	}